﻿<%@ Control Language="C#" Inherits="System.Web.Mvc.ViewUserControl<List<CRM.Database.Model.Equipments>>" %>
<%--<%@ Control Language="C#" Inherits="System.Web.Mvc.ViewUserControl<IEnumerable<CRM.Models.Equipments>>" %>--%>
<%@ Import Namespace="CRM.Models" %>
<%@ Import Namespace="CRM.Resourses" %>
<%@ Import Namespace="System.Threading" %>

<% Html.DevExpress().GridView(settings =>
                                    {
                                        settings.Name = "gdEquipments";
                                        settings.KeyFieldName = "IdEquipment";
                                        settings.CallbackRouteValues =
                                            new { Controller = "Dictionaries", Action = "EquipmentsPartial" };
                                        settings.SettingsPager.PageSize = 20;

                                        //добавление панели группировки
                                        settings.Settings.ShowGroupPanel = true;
                                        settings.Settings.ShowFilterRow = true;
                                        //
                                        
                                        settings.Columns.Add(column =>
                                        {
                                            column.Caption = Resourses.Model;
                                            column.FieldName = "Model";
                                        });

                                        //
                                        //Добавление комбобоксов
                                        //
                                        settings.Columns.Add(column =>
                                        {
                                            column.FieldName = "IdEquipmentType";
                                            column.Caption = Resourses.EquipmentType;
                                            column.ColumnType = MVCxGridViewColumnType.ComboBox;
                                            var comboBoxProperties = column.PropertiesEdit as ComboBoxProperties;
                                            if (comboBoxProperties != null)
                                            {
                                                var col = new CRM.Database.Model.EquipmentTypesCollection();
                                                comboBoxProperties.DataSource = col.EquipmentTypesActiveList;
                                                //comboBoxProperties.DataSource = DB.GetLocalizedEquipmentTypes();
                                                    //collection.EquipmentTypes;
                                                comboBoxProperties.TextField = "LocalizedName";
                                                comboBoxProperties.ValueField = "IdEquipmentType";
                                                comboBoxProperties.ValueType = typeof(int);
                                            }
                                        });

                                        settings.Columns.Add(column =>
                                        {
                                            column.FieldName = "IdVendor";
                                            column.Caption = Resourses.ToolVendor;
                                            column.ColumnType = MVCxGridViewColumnType.ComboBox;
                                            var comboBoxProperties = column.PropertiesEdit as ComboBoxProperties;
                                            if (comboBoxProperties != null)
                                            {
                                                var col = new CRM.Database.Model.VendorsCollection();
                                                comboBoxProperties.DataSource = col.VendorsActiveList;
                                                //comboBoxProperties.DataSource = DB.Vendors;
                                                comboBoxProperties.TextField = "VendorName";
                                                comboBoxProperties.ValueField = "IdVendor";
                                                comboBoxProperties.ValueType = typeof(int);
                                            }
                                        });
                                        
                                        settings.Columns.Add(column =>
                                        {
                                            column.Caption = Resourses.IsActive;
                                            column.FieldName = "IsActive";
                                            column.ColumnType = MVCxGridViewColumnType.CheckBox;
                                        });
                                        
                                        //
                                        //Добавление редактирования
                                        //
                                        
                                        settings.CommandColumn.Visible = true;
                                        settings.CommandColumn.NewButton.Visible = true;
                                        settings.CommandColumn.DeleteButton.Visible = true;
                                        settings.CommandColumn.EditButton.Visible = true;
                                        settings.SettingsBehavior.ConfirmDelete = true;
                                        settings.Settings.ShowFilterRow = true;
                                        settings.SettingsEditing.UpdateRowRouteValues = new { Controller = "Dictionaries", Action = "EquipmentsPartialUpdate" };
                                        settings.SettingsEditing.AddNewRowRouteValues = new { Controller = "Dictionaries", Action = "EquipmentsPartialAdd" };
                                        settings.SettingsEditing.DeleteRowRouteValues = new { Controller = "Dictionaries", Action = "EquipmentsPartialDelete" };

                                        settings.SettingsEditing.Mode = GridViewEditingMode.EditFormAndDisplayRow;
                                        settings.Width = Unit.Percentage(100);
                                        
                                    })
       .Bind(Model).GetHtml();
%>

